home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F26994_CreateEmployeeElements.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2001-10-04  |  2.4 KB  |  71 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- ===========================================================
  3.   Category:       XSLT
  4.   Sub-category:   xsl:element
  5.   Author:         David Silverlight
  6.                   HeadGeek@xmlpitstop.com
  7.   Created:        2001-05-16
  8.   Description:-
  9.     This stylesheet processes a set of XML elements as input and
  10.     creates a new set of xml elements as output.  In this
  11.     example we are using the several xslt functions along with
  12.     xsl:element to create two new xml elements(firstname and
  13.     lastname) from our input as well as creating a third
  14.     element directly from the xml input (department).
  15. ================================================================ -->
  16. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  17. <xsl:output method="xml"/>
  18.  
  19.  
  20.  
  21. <!-- Template for root rule -->
  22. <xsl:template match="/">
  23.     <xsl:apply-templates/>
  24. </xsl:template>
  25.  
  26.  
  27. <!-- Template for "employees" elements -->
  28. <xsl:template match="employees">
  29.     <!--This stylesheet processes a set of XML elements and 
  30.     uses the xsl:element element to generate a new xml file containing elements
  31.     in their original form as well as newly generated elements such as firstname
  32.     and lastname.-->
  33.  
  34.     <!-- Generate the "employees element" -->
  35.     <xsl:element name="bademployees" >
  36.  
  37.  
  38.     <xsl:for-each select="employee" >
  39.  
  40.         <xsl:sort select="department" order="ascending" />
  41.         <xsl:element name="employee" >
  42.  
  43.             <xsl:element name="department">
  44.                 <xsl:value-of select="department"/>
  45.              </xsl:element>
  46.  
  47.  
  48.             <!-- Here we are creating an element that is a variation from 
  49.             the original source document.  In this example we are breaking
  50.             up employee name into two seperate elements (firstname and lastname) -->
  51.             <xsl:element name="firstname">
  52.                 <xsl:value-of select="substring-before(employeename, ' ')" />
  53.             </xsl:element>
  54.  
  55.  
  56.             <!-- We can also create variables set with contents that we create and use the
  57.                  variables in our elements. Note: We are doing the same as with firstname
  58.                  but just accomplishing it with the use of an xsl:varialbe. -->
  59.             <xsl:element name="lastname">
  60.                  <xsl:variable name="lastname" select="substring-after(employeename, ' ')" />
  61.                 <xsl:value-of select="$lastname" />
  62.             </xsl:element>
  63.  
  64.         </xsl:element>
  65.     </xsl:for-each>
  66.     </xsl:element>
  67. </xsl:template>
  68.  
  69.  
  70.  
  71. </xsl:stylesheet>